package com.lin.jfreeChart;

import java.awt.Font;

import org.jfree.chart.ChartFactory;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.axis.CategoryAxis;
import org.jfree.chart.axis.CategoryLabelPositions;
import org.jfree.chart.axis.NumberAxis;
import org.jfree.chart.plot.CategoryPlot;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.chart.title.LegendTitle;
import org.jfree.chart.title.TextTitle;
import org.jfree.data.category.CategoryDataset;
import org.jfree.data.category.DefaultCategoryDataset;

import com.opensymphony.xwork2.ActionSupport;

public class LineChart3DActio extends ActionSupport {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private JFreeChart chart;

	public JFreeChart getChart() {
		chart = ChartFactory.createLineChart3D("图书销量统计图", "图书", "销量", getDataSet(),

				PlotOrientation.VERTICAL, true, false, false);

		chart.setTitle(new TextTitle("图书销量统计图", new Font("黑体", Font.ITALIC, 22)));

		LegendTitle legend = chart.getLegend(0);

		legend.setItemFont(new Font("宋体", Font.BOLD, 14));

		CategoryPlot plot = (CategoryPlot) chart.getPlot();

		CategoryAxis categoryAxis = plot.getDomainAxis();

		categoryAxis.setLabelFont(new Font("宋体", Font.BOLD, 22));

		categoryAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_45);
		categoryAxis.setTickLabelFont(new Font("宋体", Font.BOLD, 18));

		NumberAxis numberAxis = (NumberAxis) plot.getRangeAxis();

		numberAxis.setLabelFont(new Font("宋体", Font.BOLD, 22));
		return chart;
	}

	private static CategoryDataset getDataSet() {

		DefaultCategoryDataset dataset = new DefaultCategoryDataset();
		dataset.addValue(45000, "北京", "疯狂Java讲义");
		dataset.addValue(38000, "北京", "轻量级Java EE企业实战");
		dataset.addValue(24000, "北京", "疯狂Ajax讲义");
		dataset.addValue(32000, "北京", "Struts 2权威指南");
		dataset.addValue(21000, "北京", "疯狂XML讲义");
		dataset.addValue(37000, "上海", "疯狂Java讲义");
		dataset.addValue(36000, "上海", "轻量级Java EE企业实战");
		dataset.addValue(34000, "上海", "疯狂Ajax讲义");
		dataset.addValue(42000, "上海", "Struts 2权威指南");
		dataset.addValue(12000, "上海", "疯狂XML讲义");
		dataset.addValue(42000, "广州", "疯狂Java讲义");
		dataset.addValue(40000, "广州", "轻量级Java EE企业实战");
		dataset.addValue(34000, "广州", "疯狂Ajax讲义");
		dataset.addValue(18000, "广州", "Struts 2权威指南");
		dataset.addValue(26000, "广州", "疯狂XML讲义");
		return dataset;
	}
}
